#demo default parameters passing - call-by-reference.
 
#When arrays or scalars are passed to a subroutine, the default in Perl
#is "call-by-reference". The @_ array is a local array whose values are
#implicit references to the actual parameters. If you modify the @_ array,
#you will modify the actual parameters. However, if you shift or pop off
#elements of the @_ array, you merely lose the reference to the actual parameters.
sub params
{
	print "Values in @_ arrary are " . "@_\n";
	
	print "The number of elements in \@_ is " . @_ . "\n";
	#@_ lose the 1st reference of real para
	print "The 1st value is " . shift(@_) . "\n";
	#@_ lose the last reference of real para
	print "The last value is " . pop(@_) . "\n";
	print "The number of elements in \@_ is " . @_ . "\n";
	
	foreach $value (@_)
	{
		$value += 5;
	}
}

my @nums = ( 1, 2, 3, 4, 5 );
params(@nums);
print "New values are @nums.\n";
#Result:
#Values in 1 2 3 4 5 arrary are 1 2 3 4 5
#The number of elements in @_ is 5
#The 1st value is 1
#The last value is 5
#The number of elements in @_ is 3
#New values are 1 7 8 9 5.


#--------------------------------------------------------------------
sub strTest
{
	my ($str) = @_;
	$str = "abc";
}

my $str = "def";
strTest($str);
print "$str\n";

#--------------------------------------------------------------------
sub intTest
{
	my ($int) = @_;
	$int = 100;
}
my $int = 200;
intTest($int);
print "$int\n";


#--------------------------------------------------------------------
sub strTest1
{
	@_[0] = "abc";
}

my $str = "def";
strTest1($str);
print "$str\n";

#--------------------------------------------------------------------
sub intTest1
{
	@_[0] = 100;
}

my $int = 200;
intTest1($int);
print "$int\n";